<#--
/*
 * $Id: form-close.ftl 11 2009-03-27 06:33:32Z a.ruggles $
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
-->
<#if parameters.label?exists>
	</div>
</#if>
</div>
</form>
<#if ((parameters.validate?default(false) == true) && (parameters.performValidation?default(false) == true))>
<script type="text/javascript">
    function validateForm_${parameters.id}(form) {
        var validated = true;
        var field;
    <#assign fieldName="" />
    <#list parameters.tagNames as tagName>
        <#list tag.getValidators("${tagName}") as validator>
        	<#if fieldName != validator.fieldName>
        		<#if fieldName != "">
        }
        		</#if>
        		<#assign fieldName = validator.fieldName />
        field = form.elements['${validator.fieldName}'];
        Validate.clearMessages(field);
        // field name: ${validator.fieldName}
        if (field) {
            // validator name: ${validator.validatorType}
            var msg = "${validator.getMessage(action)?js_string}";
        	<#else>
            // validator name: ${validator.validatorType}
            msg = "${validator.getMessage(action)?js_string}";
        	</#if>
            <#if validator.validatorType = "required">
            if (Validate.isEmpty(field, msg)) {
                validated = false;
            }
            <#elseif validator.validatorType = "requiredstring">
            if (Validate.isStringEmpty(field, msg)) {
                validated = false;
            }
            <#elseif validator.validatorType = "stringlength">
            if (!Validate.isStringInRange(field, msg, ${validator.minLength?string}, ${validator.maxLength?string}, <#if validator.trim>true<#else>false</#if>)) {
                validated = false;
            } 
            <#elseif validator.validatorType = "regex">
            if (!Validate.matchesRegEx(field, msg, "${validator.expression?js_string}")) {
                validated = false;
            }
            <#elseif validator.validatorType = "email">
            if (!Validate.isEmail(field, msg)) {
                validated = false;
            }
            <#elseif validator.validatorType = "url">
            if (!Validate.isUrl(field, msg)) { 
                validated = false;
            }
            <#elseif validator.validatorType = "int">
            var min = <#if validator.min?exists>${validator.min?string}<#else>null</#if>;
            var max = <#if validator.max?exists>${validator.max?string}<#else>null</#if>;
            if (!Validate.isIntInRange(field, msg, min, max)) {
                 validated = false;
            }
            <#elseif validator.validatorType = "double">
            var min = <#if validator.minInclusive?exists>${validator.minInclusive?string}<#else>null</#if>;
            var max = <#if validator.maxInclusive?exists>${validator.maxInclusive?string}<#else>null</#if>;
            var minEx = <#if validator.minExclusive?exists>${validator.minExclusive?string}<#else>null</#if>;
            var maxEx = <#if validator.maxExclusive?exists>${validator.maxExclusive?string}<#else>null</#if>;
            if (!Validate.isFloatInRange(field, msg, min, max)
            	|| !Validate.isFloatInRangeExclusive(field, msg, minEx, maxEx)) {
                validated = false;
            }
            <#elseif validator.validatorType = "fieldexpression">
            if (!Validate.matchesFieldExpression(form, field, msg, "${validator.expression?js_string}")) {
                validated = false;
            }
            </#if>
        </#list>
    </#list>
    	<#if fieldName != "">
        }
        </#if>
        return validated;
    }
</script>
</#if>